﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;

namespace WindowsForms
{
    class DBHelper
    {

        private string connString = " Data Source=127.0.0.1;Initial Catalog=KTV;Persist Security Info=True;User ID=sa;Password=123456@qwe ";

        private SqlConnection connection;

        public SqlConnection Connection
        {

            get
            {

                if (connection == null)
                {
                    connection = new SqlConnection(connString);
                }
                return connection;
            }

        }


        public void OpenConnection()
        {

            if (Connection.State == System.Data.ConnectionState.Closed)
            {

                Connection.Open();

            }
            else if (Connection.State == System.Data.ConnectionState.Broken)
            {


                Connection.Close();
                Connection.Open();

            }

        }

        public void CloseConnection()
        {

            if (Connection.State == System.Data.ConnectionState.Open || Connection.State == System.Data.ConnectionState.Broken)
            {

                Connection.Close();


            }

        }


    }
}